//
//  HWVoiceRoomGiftPageView.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/8/27.
//

import UIKit
import JXSegmentedView
class HWVoiceRoomGiftPageView: UIView {
    var bannerView: SDCycleScrollView!
    var bannerGroup:[String] = Array()
    var didSelectGift:((_:HWVoiceRoomGiftModel)->())?
    var models:[[HWVoiceRoomGiftModel]]?{
        didSet{
            bannerGroup.removeAll()
            for _ in models ?? []{
                bannerGroup.append("")
            }
            bannerView.localizationImageNamesGroup = bannerGroup
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
extension HWVoiceRoomGiftPageView: JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return self
    }
}

extension HWVoiceRoomGiftPageView {
    private func initUI() -> Void {
        bannerView = SDCycleScrollView.init(frame: CGRect.zero, delegate: self, placeholderImage: nil)
        bannerView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic
        bannerView.backgroundColor = UIColor.clear
        bannerView.scrollDirection = UICollectionView.ScrollDirection.horizontal
        bannerView.autoScroll = false
        bannerView.infiniteLoop = false
        bannerView.layer.masksToBounds = true
        bannerView.localizationImageNamesGroup = ["","",""]
        
//        bannerView.layer.cornerRadius = 10
        addSubview(bannerView)
    }
    
    private func initFrame() -> Void {
        bannerView.snp.makeConstraints { make in
            make.left.top.right.bottom.equalTo(0)
        }
    }
}
extension HWVoiceRoomGiftPageView:SDCycleScrollViewDelegate{
    func customCollectionViewCellClass(for view: SDCycleScrollView!) -> AnyClass! {
        return HWVoiceRoomGiftCenterBgCell.self
    }
    
    func setupCustomCell(_ cell: UICollectionViewCell!, for index: Int, cycleScrollView view: SDCycleScrollView!) {
        let collectionCell = cell as! HWVoiceRoomGiftCenterBgCell
        
        collectionCell.models = self.models?[index]
        collectionCell.didSelectGift = {
            mod in
            self.didSelectGift?(mod)
        }
//        if models?.count ?? 0 > 0 {
//            collectionCell.model = models?[index]
//            collectionCell.createOrderCallBack = {
//                self.createOrderCallBack!($0)
//            }
//        }
    }
    
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didScrollTo index: Int) {
        
    }
    
    
}
